﻿// =================================================================== 
// 模块说明
//====================================================================
// 创建时间：2018-12-20 11:46:45
// 负责人：Sushee
// ===================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq.Expressions;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using System.Text;
namespace OF.Component.DAL
{

    /// <summary>
    /// 数据访问层
    /// </summary>	
    internal partial class CityOpen
    {

        /// <summary>
        /// 根据断言条件获取单个
        /// </summary>
        public CityOpenInfo QuerySingle(Expression<Func<CityOpenInfo, bool>> predicate)
        {
            return SQLServerProvider.CreateObject(ConnectionStringKey, predicate);
        }
        /// <summary>
    	/// 根据断言条件获获取列表
    	/// </summary>
	    public IList<CityOpenInfo> QueryList(Expression<Func<CityOpenInfo, bool>> predicate)
        {
            return SQLServerProvider.CreateList(ConnectionStringKey, predicate);
        }

        /// <summary>
        /// 查询分页列表
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public IList<CityOpenInfo> GetListByProviceId(int provinceId)
        {
            IList<CityOpenInfo> list = new List<CityOpenInfo>();
            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetStoredProcCommand("[p_CityOpen_search]");
            //设置参数
            db.AddInParameter(dbc, "@ProvinceId", DbType.Int32, provinceId);
            using (IDataReader dr = db.ExecuteReader(dbc))
            {
                while (dr.Read())
                {
                    list.Add(SQLServerProvider.Create<CityOpenInfo>(dr));
                }
            }
            return list;
        }

        /// <summary>
        /// 获取所有的开放城市
        /// </summary>
        /// <returns></returns>
        public DataTable GetAllOpenCity()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT T.CityID,T.CityName,T1.locationSpellName FROM CityOpen T WITH(NOLOCK) ");
            strSql.Append("LEFT JOIN [BaseFrameworkDev].dbo.BaseLocation_All T1 WITH(NOLOCK) ON T.CityID = T1.locationId ");
            strSql.Append("WHERE T.Status=1 ");
            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetSqlStringCommand(strSql.ToString());
            DataSet ds = db.ExecuteDataSet(dbc);
            return ds.Tables[0];
        }
    }

}